package com.huanwei.http;

import android.util.Log;

import com.huanwei.cc.base.MyApplication;
import com.huanwei.cc.newbean.Login;
import com.huanwei.cc.newbean.LoginT;
import com.huanwei.cc.utils.ALL_CONFIG;
import com.huanwei.cc.utils.JSONUtils;
import com.huanwei.cc.utils.SpfUtils;
import com.huanwei.login_regist.LoginActivity;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by 他的猫 on 2017/5/10.
 */

public class API {
    /**
     * 轨迹回放
     *
     * @param
     * @param handler
     */
    public static void VehicleTrack(String number,
                                    Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("number", number);

        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "车辆轨迹回放" + jg2);
        Okhttp.post(getBase() + "XueXi_2019/Achievement/QueryAchievementsbykemu", map, handler);

    }

    public static String getBase() {
        String ip = (String) SpfUtils.get(MyApplication.getInstance(), "ip", "192.168.43.1");
        String url = "http://" + ip + ":8080/";
        return url;
    }

    public static LoginT getTeacher() {

        String telogin = (String) SpfUtils.get(MyApplication.getInstance(), "telogin", "");
        LoginT loginT = JSONUtils.parseJSON(telogin, LoginT.class);

        return loginT;
    }

    public static Login getStudent() {

        String telogin = (String) SpfUtils.get(MyApplication.getInstance(), "stlogin", "");
        Login loginT = JSONUtils.parseJSON(telogin, Login.class);

        return loginT;
    }

    /**
     * 登录 1
     *
     * @para
     */
    public static void login(String username, String password, String type, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_account", username);
        map.put("user_password", password);
        if (type.equals("1")) {
            Okhttp.post(getBase() + "XueXi_2019/Student/Studentlogin", map, handler);
        } else {
            Okhttp.post(getBase() + "XueXi_2019/Teacher/Teacherlogin", map, handler);
        }


    }

    /**
     * 学生注册
     *
     * @param handler
     */
    public static void Studentregister(String username, String password, String name,
                                       String number, String sex, String xi,
                                       String banji,
                                       Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_account", username);
        map.put("user_password", password);
        map.put("user_name", name);

        map.put("number", number);
        map.put("sex", sex);
        map.put("xi", xi);
        map.put("banji", banji);
        Okhttp.post(getBase() + "XueXi_2019/Student/Studentregister", map, handler);

    }

    /**
     * 老师注册
     *
     * @param handler
     */
    public static void Teacherregister(String username, String password, String name,
                                       String number, String zhicheng, String xi,
                                       String banji,
                                       Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("user_account", username);
        map.put("user_password", password);
        map.put("user_name", name);
        map.put("xi", xi);
        map.put("zhicheng", zhicheng);
        map.put("number", number);
        map.put("banji", banji);
        Okhttp.post(getBase() + "XueXi_2019/Teacher/Teacherregister", map, handler);

    }


    /**
     * 学生签到
     *
     * @param handler
     */
    public static void StudentSign(String teacher_name,
                                   String teacher_number, String kecheng_name, String time,
                                   String shijianduan,
                                   Okhttp.Objectcallback handler) {
        Login.DataBean data = getStudent().getData();

        Map<String, String> map = new HashMap<>();
        map.put("student_name", data.getUser_name());
        map.put("student_number", data.getNumber());
        map.put("teacher_name", teacher_name);
        map.put("teacher_number", teacher_number);
        map.put("kecheng_name", kecheng_name);
        map.put("time", time);
        map.put("shijianduan", shijianduan);
        map.put("address", ALL_CONFIG.Latitude + "," + ALL_CONFIG.Longitude);
        Okhttp.post(getBase() + "XueXi_2019/Sign/addSign", map, handler);

    }

    /**
     * 警察上班
     *
     * @param handler
     */
    public static void TeacherSign(String type,
                                   Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("id", getStudent().getData().getId());
        map.put("address", ALL_CONFIG.Latitude + "," + ALL_CONFIG.Longitude);
        map.put("type", type);
        Okhttp.post(getBase() + "XueXi_2019/Student/StudentSign", map, handler);

    }


    /**
     * 获得老师列表
     *
     * @param handler
     */
    public static void getTeachers(
            Okhttp.Objectcallback handler) {

        Okhttp.post(getBase() + "XueXi_2019/Teacher/getTeachers", null, handler);

    }

    /**
     * 获得老师信息
     *
     * @param handler
     */
    public static void getTeachermessage(String student_name,
                                         Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("teacher_name", student_name);
        Okhttp.post(getBase() + "XueXi_2019/Teacher/getTeacherbyname", map, handler);

    }

    /**
     * 添加课程
     *
     * @param handler
     */
    public static void addCurriculum(String subject_name, String teacher_name, String week,
                                     String shijianduan, String address, String xi,
                                     String class_s,
                                     Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("subject_name", subject_name);
        map.put("teacher_name", teacher_name);
        map.put("week", week);
        map.put("shijianduan", shijianduan);
        map.put("address", address);
        map.put("xi", xi);
        map.put("class_s", class_s);

        Okhttp.post(getBase() + "XueXi_2019/Curriculum/addCurriculum", map, handler);

    }

    /**
     * 添加课程
     *
     * @param handler
     */
    public static void addmyCurriculum(String subject_name, String teacher_name, String week,
                                       String shijianduan, String address, String xi,
                                       String class_s,
                                       Okhttp.Objectcallback handler) {
        String number = getStudent().getData().getNumber();


        Map<String, String> map = new HashMap<>();
        map.put("subject_name", subject_name);
        map.put("teacher_name", teacher_name);
        map.put("week", week);
        map.put("shijianduan", shijianduan);
        map.put("address", address);
        map.put("student_number", number);
        Okhttp.post(getBase() + "XueXi_2019/StudentCurriculum/addCurriculum", map, handler);

    }

    /**
     * 获得课程列表
     *
     * @param handler
     */
    public static void getCurriculums(
            Okhttp.Objectcallback handler) {

        Okhttp.post(getBase() + "XueXi_2019/Curriculum/getCurriculums", null, handler);

    }

    /**
     * 删除课程
     *
     * @param handler
     */
    public static void detelCurriculum(String id,
                                       Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);

        Okhttp.post(getBase() + "XueXi_2019/Curriculum/detel", map, handler);

    }

    /**
     * 获得学生列表
     *
     * @param handler
     */
    public static void getStudents(
            Okhttp.Objectcallback handler) {

        Okhttp.post(getBase() + "XueXi_2019/Student/getStudents", null, handler);

    }


    /**
     * 获得学生列表
     *
     * @param handler
     */
    public static void getChengJi(
            Okhttp.Objectcallback handler) {
        String id = getStudent().getData().getNumber();
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        Okhttp.post(getBase() + "XueXi_2019/Achievement/QueryAchievement", map, handler);

    }

    /**
     * 获得考勤列表
     *
     * @param handler
     */
    public static void getSignbystudentid(
            Okhttp.Objectcallback handler) {


        Okhttp.post(getBase() + "XueXi_2019/Client/QueryClient", null, handler);

    }

    /**
     * 获得课程列表
     *
     * @param handler
     */
    public static void getmyCurriculums(
            Okhttp.Objectcallback handler) {
        String number = getStudent().getData().getNumber();
        Map<String, String> map = new HashMap<>();
        map.put("id", number);
        Okhttp.post(getBase() + "XueXi_2019/Student/getStudents2s", map, handler);

    }

    /**
     * 获得签到列表
     *
     * @param handler
     */
    public static void getsign(
            Okhttp.Objectcallback handler) {

        Okhttp.post(getBase() + "XueXi_2019/Sign/getSigns", null, handler);

    }

    /**
     * 获得老师授课列表
     *
     * @param handler
     */
    public static void getCurriculumsbyteacher(
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();
        String teacher_name = getTeacher().getData().getUser_name();
        map.put("teacher_name", teacher_name);
        Okhttp.post(getBase() + "XueXi_2019/Curriculum/getCurriculums", map, handler);

    }


    /**
     * 修改学生的
     *
     * @param handler
     */
    public static void getXiuGaiSt(String sex, String diqu,
                                   Okhttp.Objectcallback handler) {
        String number = getStudent().getData().getNumber();
        Map<String, String> map = new HashMap<>();
        map.put("student_number", number);
        map.put("sex", sex);
        map.put("diqu", diqu);
        Okhttp.post(getBase() + "XueXi_2019/Student/StudentUp", map, handler);

    }

    /**
     * 修改老师的
     *
     * @param handler
     */
    public static void getXiuGaiTe(String zhicheng, String diqu,
                                   Okhttp.Objectcallback handler) {
        String number = getTeacher().getData().getNumber();
        Map<String, String> map = new HashMap<>();
        map.put("number", number);
        map.put("zhicheng", zhicheng);
        map.put("diqu", diqu);
        Okhttp.post(getBase() + "XueXi_2019/Teacher/TeacherUp", map, handler);

    }


    /**
     * kemu
     *
     * @param handler
     */
    public static void ChaXunChengJi(String kemu,
                                     Okhttp.Objectcallback handler) {

        Map<String, String> map = new HashMap<>();
        map.put("kemu", kemu);

        Okhttp.post(getBase() + "XueXi_2019/Achievement/QueryAchievementsbykemu", map, handler);

    }


    /**
     * 获得学生列表
     *
     * @param handler
     */
    public static void QueryAchievements(
            Okhttp.Objectcallback handler) {
        String id = getStudent().getData().getNumber();

        Okhttp.post(getBase() + "XueXi_2019/Achievement2/QueryAchievements2", null, handler);

    }


    /**
     * 递交反馈
     *
     * @param handler
     */
    public static void DiJiaoFanKui(String id, String kemu,
                                    Okhttp.Objectcallback handler) {

        Map<String, String> map = new HashMap<>();
        map.put("kemu", kemu);
        map.put("id", id);

        Okhttp.post(getBase() + "XueXi_2019/Achievement2/gengxinfanki", map, handler);

    }


    /**
     * 递交反馈
     *
     * @param handler
     */
    public static void sousuo(Map<String, String> map,
                              Okhttp.Objectcallback handler) {


        Okhttp.post(getBase() + "XueXi_2019/Client/sousuo", map, handler);

    }
}
